package cn.wolfcode.wolf2world.web.controller;

import cn.wolfcode.wolf2world.domain.Destination;
import cn.wolfcode.wolf2world.query.DestinationQueryObject;
import cn.wolfcode.wolf2world.service.DestinationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author 杨兴健
 * @Date 2020-08-11 19:00
 */
@Controller
@RequestMapping("/destination")
public class DestinationController {
    @Autowired
    private DestinationService destinationService;

    /**
     * 目的地高级查询
     * @param model
     * @param qo 查询条件
     * @return
     */
    @RequestMapping("/list")
    public String query(Model model, @ModelAttribute("qo") DestinationQueryObject qo) {
        Page<Destination> page = destinationService.query(qo);
        model.addAttribute("page",page);

        List<Destination> list = destinationService.toasts(qo.getParentId());
        model.addAttribute("toasts",list);
        return "destination/list";
    }


    /**
     * 修改简介
     * @param id
     * @param info
     * @return
     */
    @RequestMapping("/updateInfo")
    @ResponseBody
    public Object updateInfo(String id,String info) {
        destinationService.updateInfo(id,info);
        Map map = new HashMap();
        map.put("success",true);
        return map;
    }

    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(Integer deep) {
        List<Destination> list = destinationService.queryByDeep(deep);
        return list;
    }

}
